AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")

include('shared.lua')

function ENT:SpawnFunction( pl , tr , caller )
	
	local headcrabs , m = ents.FindByClass( "headcrabhat", "conehat" );
	for _ , m in pairs( headcrabs ) do
		if ( m && m:IsValid( ) && m:GetOwner( ) == pl ) then
			return;
		end
	end
	
	
	local eyes = pl:LookupAttachment( 'anim_attachment_head' );
	
	if ( eyes == 0 ) then return; end
	
	
	local headcrab = ents.Create( 'headcrabhat' );
	
	
	headcrab:SetOwner( pl );
	headcrab:SetParent( pl );
	headcrab:SetModel("models/Nova/w_headcrab.mdl")
	
	
	local attachment = pl:GetAttachment( eyes );
	
	
	local pos = attachment.Pos
	headcrab:SetPos( pos );

	
	local ang = attachment.Ang;
	local temp = ang.r
	ang.y = ang.y
	ang.r = ang.p + 90
	ang.p = ((temp - 90)*-1) -10
	headcrab:SetAngles( ang );	
	
	
	headcrab:Spawn( );
	headcrab:Activate( );
	
	
	headcrab:Fire( "SetParentAttachment", "anim_attachment_head" )
	headcrab:SetMoveType( MOVETYPE_NONE )
	headcrab:SetSolid( SOLID_NONE )
	headcrab:SetCollisionGroup( COLLISION_GROUP_NONE )
	headcrab:DrawShadow( false )
	
	
	
	return headcrab;
end

function ENT:Think()
if self.Entity:GetOwner():GetViewEntity():GetClass() == "gmod_cameraprop" then
	self.Entity:GetOwner():SetNWBool(	"Camera",			true)
	else
	self.Entity:GetOwner():SetNWBool(	"Camera",			false)
	end
	end
	